function except(a, b, k) {
  return [...a, ...b].filter(
    (i) =>
      ![a, b].every((t) =>
        k ? t.map((i) => i[k]).includes(i[k]) : t.includes(i)
      )
  )
}

const a = [1, 2, 3, 4, 5]
const b = [1, 2, 4, 5, 6]

console.log(except(a, b))

const a1 = [
  { id: 1, name: '张三', age: 20 },
  { id: 2, name: '李四', age: 21 },
  { id: 3, name: '小二', age: 23 },
]

const b1 = [
  { id: 2, name: '李四', age: 21 },
  { id: 4, name: '小明', age: 24 },
  { id: 5, name: '小红', age: 25 },
]

console.log(except(a1, b1, 'id'))
